<extend name="Common/common"/>

<block name="content">
<link rel="stylesheet" href='__PUBLIC_ADMIN__css/caidanEdit.css'/>
<div id="content">
<empty name="id">
	<p>请在右侧选择菜单</p>
</empty>
<if condition="$haveSub == 1">
	<div class="bg">
		<div class="nav">
			<span id="title">{$caidan['name']}</span>
			<a href="javascript:" onclick="caidanDel(1,'{:U("caidanDel",array('id'=>$id))}')">删除菜单</a>
		</div>
		<p>已添加子菜单，仅可设置菜单名称。</p>
		<form action="" method="post" class="form form-horizontal" id="form-member-add">
			<div class="row cl">
				<label class="form-label col-xs-3"><span class="c-red">*</span>菜单名称：</label>
				<div class="formControls col-xs-7">
					<input type="text" class="input-text radius" value="{$caidan['name']}" placeholder="" name="name">
				</div>
			</div>
			<input type="hidden" name='id' value="{$id}"/>
			<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;保存&nbsp;&nbsp;">
		</form>
	</div>
</if>
<if condition="$haveSub == 2">
	<div class="bg">
		<div class="nav">
			<span id="title">{$caidan['name']}</span>
			<a href="javascript:" onclick="caidanDel(0,'{:U("caidanDel",array('id'=>$id))}')">删除子菜单</a>
		</div>
		<form action="" method="post" class="form form-horizontal" id="form-member-add">
			<div class="row cl">
				<label class="form-label col-xs-3"><span class="c-red">*</span>菜单名称：</label>
				<div class="formControls col-xs-7">
					<input type="text" class="input-text radius" value="{$caidan['name']}" placeholder="" name="name">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-3"><span class="c-red">*</span>菜单内容：</label>
				<div class="formControls col-xs-7 skin-minimal">
				  <div class="radio-box" onclick="sendMessage()" id="msg">
			          <input type="radio" id="sex-1" name="type" value="1" <if condition="$caidan['type'] == 1">checked</if>>
			          <label onclick="sendMessage()" for="sex-1">发送消息</label>
			        </div>
			        <div class="radio-box" onclick="setUrl()" onclick="setUrl()" id="url">
			          <input type="radio" id="sex-2" name="type" value="2" <if condition="$caidan['type'] == 2">checked</if>>
			          <label for="sex-2" onclick="setUrl()">跳转网页</label>
			        </div>
				</div>
			</div>
			<div class="row cl msg_con <if condition="$caidan['type'] == 2">hidden</if>">
		      <label class="form-label col-xs-3">消息内容：</label>
		      <div class="formControls col-xs-7">
		        <textarea name="content" cols="" rows="" class="textarea" >{$caidan['content']}</textarea> 
		      </div>
		    </div>
		    <div class="row cl url_con <if condition="$caidan['type'] == 1">hidden</if>">
		      <label class="form-label col-xs-3">链接地址：</label>
		      <div class="formControls col-xs-7">
		        <input type="text" class="input-text radius" value="{$caidan['url']}" placeholder="" name='url'>
		      </div>
		    </div>
		    <input type="hidden" name='id' value="{$id}"/>
			<input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;保存&nbsp;&nbsp;">
		</form>
	</div>
</if>
</div>
<script>
function caidanDel(type,url){
	var msg = '';
	if(type == 1){
		msg = '删除彩菜单会把子菜单一起删除';
	}else{
		msg = '确定删除子菜单';
	}
	var index = layer.confirm(msg, {
		  btn: ['确定','取消'] //按钮
		}, function(){
		  layer.close(index);
		  $.get(url,function(res){
			  if(res == 1){
				  layer.msg('删除成功',{icon:6,time:1000});
				  setTimeout(function(){
					  parent.location.reload();
				  },1000);
			  }else{
				  layer.msg('删除失败',{icon:5,time:1000});
			  }
		  })
		});
}
function sendMessage(){
	$('.msg_con').removeClass('hidden');
	$('.url_con').addClass('hidden');
}
function setUrl(){
	$('.url_con').removeClass('hidden');
	$('.msg_con').addClass('hidden');
}
$(function(){
	$('.skin-minimal input').iCheck({
		checkboxClass: 'icheckbox-blue',
		radioClass: 'iradio-blue',
		increaseArea: '20%'
	});
	$('#msg').find('.iradio-blue').attr('onclick','sendMessage()');
	$('#url').find('.iradio-blue').click('setUrl');
	
	$("#form-member-add").validate({
		rules:{
			name:{
				required:true,
				minlength:2,
				maxlength:16
			},
			
		},
		onkeyup:false,
		focusCleanup:true,
		success:"valid",
		submitHandler:function(form){
			$(form).ajaxSubmit({
	        	type: 'post', // 提交方式 get/post
	            url: '{:U("caidanEdit")}', // 需要提交的 url
	            success: function(data) { // data 保存提交后返回的数据，一般为 json 数据
	            	if(data.status == 1){
	            		layer.msg('修改成功',{icon:6,time:1000});
	            		$(parent.document).find('.on').text(data.name);
	            		$('#title').text(data.name);
	            	}else{
	            		layer.msg(data.msg,{icon:5,time:1000});
	            	}
	            }
	        });
		}
	});
});
</script>
</block>